
//获取加工厂信息
export const FactoryInfoMixin = {
  methods: {
	//获取工厂信息，判断审核状态
    async currentFactoryInfo(){
	 await this.$store.dispatch('getCurrentFactory').then(res=>{
		//审核状态（0待认证；1待审核；2审核成功；3审核失败）
		if(res.data.data.reviewState === 0){
			uni.showToast({ title: '请完善认证信息', icon: 'none' });
			uni.redirectTo({
			    url: '/pages/authentication/authentication'
			});
		}else if(res.data.data.reviewState === 1 || res.data.data.reviewState === 3){
			uni.redirectTo({
			    url: '/pages/authentication/audit?auditInfo='+JSON.stringify(uni.getStorageSync('factoryinfo'))
			});
		}else {
			uni.switchTab({
			    url: '/pages/index/index'
			});
		}
	})
   },
  }
}

//获取共享工厂信息
export const sFactoryInfoMixin = {
  methods: {
    async sfactoryUserInfo(){
	 await this.$store.dispatch('getSfactoryUserInfo').then(res=>{
		if(res.data.errorCode === 0){
			uni.switchTab({
			    url: '/pages/index/index'
			});
		}
	})
   },
  }
}

//发送验证码
export const SendCodeMixin = {
 data(){
	 return{
		 codetime:0
	 }
 },
  methods: {
 async sendCodeUtil(mobile,type){
	 uni.removeStorageSync('token');
	 let mPattern = /^1[345678]\d{9}$/;
	 if (this.codetime > 0) return;
	 // 验证手机号合法性
	 if (!mPattern.test(mobile)) {
	 	return uni.showToast({ title: '请输入正确的手机号码', icon: 'none' });
	 }
	 let sendParams = {mobile,type};
	 await this.$store.dispatch('sendCaptcha', sendParams).then(res => {
	 		if (res.data.errorCode === 0) {
	 			uni.showToast({ title: '验证码发送成功，请注意查收', icon: 'none' });
	 			// 发送成功，开启倒计时
	 			this.codetime = 60;
	 			let timer = setInterval(() => {
	 				this.codetime--;
	 				if (this.codetime < 1) {
	 					clearInterval(timer);
	 					this.codetime = 0;
	 				}
	 			}, 1000);
	 		}
	 	})
 }
  }
}